package com.maigao.entity;

import com.maigao.entity.enums.ResultStatus;
import lombok.Data;

/**
 * @program: maigao
 * @description:
 * @author: yongza
 * @create: 2020-12-18 11:43
 **/
@Data
public class ResultJson<T> {
    private int code;
    private String msg;
    private T data;

    public ResultJson() {
    }

    public ResultJson(ResultStatus resultStatus) {
        this.code = resultStatus.getValue();
        this.msg = resultStatus.getName();
    }

    public ResultJson(ResultStatus resultStatus, T data) {
        this.code = resultStatus.getValue();
        this.msg = resultStatus.getName();
        this.data = data;
    }

    public ResultJson(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultJson(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultJson fail(String resultMsg) {
        return new ResultJson<>(ResultStatus.FAIL.getValue(), resultMsg);
    }

    public static <T> ResultJson success(T data) {
        return new ResultJson<T>(ResultStatus.SUCCESS, data);
    }
}
